package com.suixinsanren.design.state.study.demo02;

public class SoldOutState implements State {

    private final GumballMachine gumballMachine;

    public SoldOutState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("你不能投25美分硬币，这台机器已经卖完了");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("你不能弹出，你还没有插入25美分硬币");
    }

    @Override
    public void turnCrank() {
        System.out.println("你已经转动曲柄，但是已经没有糖果了");
    }

    @Override
    public void dispense() {
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() > 0) {
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        } else {
            System.out.println("已经没有糖果了");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }
}
